<template>
	<view class="mutual-lists">
		<view class="user">
			<view class="user-left">
				<image :src="userInfo.avatar ?  userInfo.avatar : require('../../../static/images/avatar.png')" mode=""></image>
				<view class="user-right">
					<text>{{userInfo.username}}</text>
					<text>ID:{{userInfo.id}}</text>
				</view>
			</view>
		</view>
		<view class="tab-content">
			<block v-for="(item,index) in data" :key="index">
				<block-pushs-item :item="item"></block-pushs-item>
			</block>
			<block-loading :status="status" :len="data.length"></block-loading>
		</view>
	</view>
</template>

<script>
	import BlockPushsItem from "@/components/BlockPushsItem/BlockPushsItem.vue"
	import {user} from "@/api/entrance.js"
	import {getUserRewards} from "@/api/reward.js"
	export default{
		name:"mutual-lists",
		components: {
			BlockPushsItem
		},
		data(){
			return{
				userInfo:{},
				data: [], //数据列表
				status:"loading",
				page:1,
			}
		},
		//上拉加载
		onReachBottom(){
			this.getPushData()
		},
		async onLoad(option) {
			if(option.uid){
				let res = await user({id:option.uid})
				if(res.code === 1){
					this.userInfo = res.data
				}
			}
			this.getPushData()
		},
		methods:{
			//加载更多数据
			async getPushData(){
				let data={
					id:this.userInfo.id,
					page:this.page,
					size:20,
				}
				let res = await getUserRewards(data);
				if(this.page===1&&res.data.length === 0){
					this.status = "nodata"
					return
				}
				if(this.page===1&&res.data.length > 0 && res.data.length < 20){
					this.status = "nomore"
				}
				if(res.data.length === 0){
					this.status = "nomore"
					return;
				}
				
				this.page++;
				this.data = this.data.concat(res.data);
			}
		},
		watch:{
			userInfo:{
				handler(newValue){
					if(newValue){
						uni.setNavigationBarTitle({
							title:newValue.username
						})
					}
				},
				immediate: true
			}
		}
	}
</script>

<style lang="less" scoped src="./mutual-lists.less">
</style>
